package com.atguigu.edu2021.mock.stage;

import com.alibaba.fastjson.JSON;
import com.atguigu.edu2021.mock.config.AppConfig;
import com.atguigu.edu2021.mock.factory.UserSession;
import com.atguigu.edu2021.mock.log.*;
import com.atguigu.mock.util.LogUtil;
import com.atguigu.mock.util.RandomNum;
import org.springframework.stereotype.Component;

@Component("startApp")
public class StartAppStage implements Stage{
    @Override
    public boolean handle() {
        log();
        return true;
    }

    private  void  log(){
        AppCommon appCommon = UserSession.getAppCommon();
        AppStart appStart = AppStart.builder().build();
        Integer durTime= RandomNum.getRandInt(5000, AppConfig.page_during_max_ms);
        UserSession.addTimeByDuringTime(durTime);
        Long ts= UserSession.getCurDateTime().getTime();
        AppMain appMain = AppMain.builder().common(appCommon).start(appStart).ts(ts).checkError().build();


        String logJson = JSON.toJSONString(appMain);
        LogUtil.log(logJson);

    }
}
